package com.hanserwei.mydemo.stream;

import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import java.util.stream.Stream;

public class CollectTest6 {

    public static void main(String[] args) {
        Stream<String> stream = Stream.of("令狐冲", "风清扬", "独孤求败", "方证", "东方不败", "冲虚", "向问天", "任我行", "不戒", "令狐冲");
        /*
        按名字长度分组
        Map
        3：new ArrayList(.....)
        4：new ArrayList(.....)
        2：new ArrayList(.....)
         */

        Map<Integer, List<String>> map = stream.collect(Collectors.groupingBy(String::length, Collectors.toList()));
        for (Map.Entry<Integer, List<String>> integerListEntry : map.entrySet()) {
            System.out.println(integerListEntry.getKey() + ":" + Arrays.toString(integerListEntry.getValue().toArray()));
        }
    }
}
